<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <input type="text" id="guessField" class="guessField"><br>
    <input type="submit" value="确定" class="guessSubmit">
    <script>
        const guessSubmit = document.querySelector('.guessSubmit');
        const guessField = document.querySelector('.guessField');
        guessField.focus();

        let r=Math.floor(Math.random()*100)+1;
       
        function fun(){
            for (let i=1;i<=10;i++){
                let a = Number(guessField.value);
                if(r===a){
                    alert("你猜对了");
                    break;
                    
                }else if(a<r){
                    alert("你猜小了");
                    alert("你还有"+(10-i)+"次机会");
                    
                    
                }else if(a>r){
                    alert("你猜大了");
                    alert("你还有"+(10-i)+"次机会");
                }
            }
        }
        guessSubmit.addEventListener('click', fun);
       
    </script>
</body>
</html>